package com.calvin.study.multithread.threadpool;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class BaseThreadPool {

	private static ExecutorService executor = null;

	public static ExecutorService getInstance() {
		if (null == executor) {
			// 线程最大8个
			executor = new ThreadPoolExecutor(10, 20, 1L, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(30),
					Executors.defaultThreadFactory(), new ThreadPoolExecutor.CallerRunsPolicy());
		}

		return executor;
	}
	
	public static String getDateStr() {
		Date curDate = new Date();
		SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(curDate);
	}
	
	public static String getCurThreadName() {
		return Thread.currentThread().getName();
	}

}
